import { EInputDataType, ProcessType, TabFieldType } from '/@/components/Linxyun/custom/DataStructs/commontype';
import { calcFieldValue } from '/@/components/linxyun/custom/CustomCommon/lxy_expression.js';
export default function useElement(located: any, FieldItem: TabFieldType, componentVal: any, props: Record<string, any>) {
	if (FieldItem?.FieldName) {
		if (FieldItem.InputDataType == EInputDataType.FrontType) {
			componentVal.value = componentVal.value || '';
		} else {
			// console.log('useElement', FieldItem.InputDataCfg);
			if (/\${.*}/.test(componentVal.value) || /^'label\..*'$/.test(componentVal.value)) {
				componentVal.value = calcFieldValue(FieldItem.InputDataType, FieldItem.InputDataCfg, props.inputData, props.pageData, props.globalData);
			}
		}
	}
	const handleStyle = () => {
		if (located.value === 'Add') {
			// console.log(FieldItem.AddColWidth ? FieldItem.AddColWidth + 'px' : '100%');
			return '100%';
		} else if (located.value === 'Edit' || located.value == 'Detail') {
			return '100%';
		} else if (located.value === 'Filter') {
			return Number(FieldItem.FilterWidth) ? FieldItem.FilterWidth + 'px' : '210px';
		}
	};

	const handleDisable = (activate: any) => {
		// console.log('handleDisable', located);
		// 是否禁用
		if (FieldItem?.AddProcessType === ProcessType.Readonly && located.value == 'Add') {
			activate.value = false;
		} else if (FieldItem?.EditProcessType === ProcessType.Readonly && located.value == 'Edit') {
			activate.value = false;
		} else if (located.value == 'Detail') {
			activate.value = false;
		} else if (FieldItem && (FieldItem.InputDataType == 1 || FieldItem.InputDataType == 2 || FieldItem.InputDataType == 3)) {
			activate.value = false;
		}
	};
	return {
		handleStyle,
		handleDisable,
	};
}
